
#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
using namespace std;
vector<int> p;
void build(int n) {
	for (p.push_back(2), p.push_back(3); *p.rbegin() < n;) {
		for (int j = *p.rbegin(), k = j + 2, i; k <= j*j; k += 2) {
			for (i = 1; i < p.size(); i++)
				if (k%p[i] == 0)
					break;
			if (i == p.size())
				p.push_back(k);
		}
	}
}
int main() {
	build(1005);
	ifstream cin("22.txt");
	for (int m; cin >> m;)
		for (int n, t,s; m-- && cin >> n;) {
			for (s=0; n-- && cin >> t;)
				if (find(p.begin(), p.end(), t) != p.end())
					s += t;
			cout << s << endl;
		}
	return 0;
}
